﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CoucheAccesDonnees
{
    public class CAD
    {
        private System.Data.SqlClient.SqlConnection cnx;
        private System.Data.SqlClient.SqlCommand cmd;
        private System.Data.SqlClient.SqlDataAdapter da;
        private System.Data.DataSet ds;
        private FactoryMessage.STGMSG oMsg;
        private string rq_sql;

        public CAD()
        {
            this.cnx = new System.Data.SqlClient.SqlConnection(@"Data Source=EBARBOLINI\MANU_SQLSERVER;Initial Catalog=DB_A2_ARCHINET_P2;User 
ID=CNX_ARCHINETP2;Password=password");
            this.cmd = new System.Data.SqlClient.SqlCommand();
            this.da = new System.Data.SqlClient.SqlDataAdapter();
            this.ds = new System.Data.DataSet();
        }

        public FactoryMessage.STGMSG get_Rows(FactoryMessage.STGMSG oMsg)
        {
            this.rq_sql = (string)oMsg.Data[0];
            this.cmd.CommandType = System.Data.CommandType.Text;
            this.cmd.CommandText = this.rq_sql;
            this.cmd.Connection = this.cnx;
            this.da.SelectCommand = cmd;
            this.da.Fill(this.ds, (string)oMsg.Data[1]);

            this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", new object[] { (object)this.ds }, "", "", "", true, "");

            return this.oMsg;
        }

        public FactoryMessage.STGMSG Action_Rows(FactoryMessage.STGMSG oMsg)
        {
            this.rq_sql = (string)oMsg.Data[0];
            this.cmd.CommandType = System.Data.CommandType.Text;
            this.cmd.CommandText = this.rq_sql;
            this.cmd.Connection = this.cnx;
            this.cnx.Open();
            this.cmd.ExecuteNonQuery();
            this.cnx.Close();

            this.oMsg = FactoryMessage.MSG_FACTORY.msg_factory("", null, "", "", "", true, "");

            return this.oMsg;
        }
    }
}
